<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons">
		<a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a>
		<a href="<?php echo $cancel_url;?>" class="button"><?php echo $button_cancel; ?></a>
	  </div>
    </div>
    <div class="content">
	  <form action="<?php echo $save_url; ?>" method="post" enctype="multipart/form-data" id="form">
        <input type="hidden" value="<?php echo $gift['id'];?>" name="id"/>
        <table id="gift-form" class="form">
			<thead>
				<tr><td><?php echo $option_name_text;?></td><td><?php echo $option_value_text;?></td></tr>
			</thead>		
			<tbody>
				<tr>
					<td><?php echo $gift_name_text;?></td>
					<td>
						<input type="text" value="<?php echo $gift['name'];?>" name="name" />
					</td>
				</tr>
				<tr>
					<td><?php echo $gift_category_text;?></td>
					<td>
						<select name="options[gift_catgory]">
							<?php foreach($categories as $category) : ?>
								<option <?php if($options['gift_catgory']== $category['category_id']) echo 'selected="selected"';?> value="<?php echo $category['category_id']?>"><?php echo $category['name']?></option>
								<?php foreach($category['children'] as $child) : ?>
								<option <?php if($options['gift_catgory']== $child['category_id']) echo 'selected="selected"';?> value="<?php echo $child['category_id']?>"><?php echo $child['name']?></option>
								<?php endforeach;?>
							<?php endforeach;?>
						</select>
					</td>
				</tr>
				<tr>
					<td><?php echo $this_gift_made_for_text;?></td>
					<td>
						<select id="made-for" name="options[this_gift_made_for]">
							<option <?php if($options['this_gift_made_for']== 'users') echo 'selected="selected"';?> value="users"><?php echo $customers_text?></option>	
							<option <?php if($options['this_gift_made_for']== 'orders') echo 'selected="selected"';?> value="orders"><?php echo $orders_text?></option>	
							<option <?php if($options['this_gift_made_for']== 'products') echo 'selected="selected"';?> value="products"><?php echo $products_text?></option>	
						</select>
						<div class="dependency">
							<div class="orders" style="<?php if($options['this_gift_made_for']== 'orders') echo 'display:block';?>">
								<label><?php echo $minimum_cart_amount_text;?></label>
								<input name="options[minimum_cart_amount]" type="text" value="<?php echo $options['minimum_cart_amount'];?>" placeholder="146" />
							</div>
							<div class="users" style="<?php if($options['this_gift_made_for']== 'users') echo 'display:block';?>">
								<label><?php echo $customers_text;?></label>
								<select name="options[user_group]">
									<?php foreach($customers_group as $group) : ?>
										<option <?php if($options['user_group']== $group['customer_group_id']) echo 'selected="selected"';?> value="<?php echo $group['customer_group_id'];?>"><?php echo $group['name'];?></option>
									<?php endforeach;?>
								</select>
							</div>
							<div class="products" style="<?php if($options['this_gift_made_for']== 'products') echo 'display:block';?>">
								<label><?php echo $products_gift_offered?> (Autocomplete)</label>
								<input type="text" name="product" value="" />
								<div id="featured-product" class="scrollbox">
								    <?php $class = 'odd'; ?>
									<?php foreach ($products as $product) { ?>
									<?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
									<div id="featured-product<?php echo $product['product_id']; ?>" class="<?php echo $class; ?>"><?php echo $product['name']; ?> <img src="view/image/delete.png" alt="" />
									  <input type="hidden" name="options[products][]" value="<?php echo $product['product_id']; ?>" />
									</div>
									<?php } ?>
								</div>
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<td><?php echo $date_start_text;?></td>
					<td><input class="date" type="text" name="date_start" value="<?php echo $gift['date_start'];?>"/></td>
				</tr>
				<tr>
					<td><?php echo $date_end_text;?></td>
					<td><input class="date" type="text" name="date_end" value="<?php echo $gift['date_end'];?>"/></td>
				</tr>
				<tr>
					<td><?php echo $mesage_text;?></td>
					<td><textarea name="options[message]"><?php echo $options['message'];?></textarea></td>
				</tr>				
			</tbody>	
        </table>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
$('.date').datepicker({dateFormat: 'yy-mm-dd'});
$('input[name=\'product\']').autocomplete({
	delay: 500,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {
				response($.map(json, function(item) {
					return {
						label: item.name,
						value: item.product_id
					}
				}));
			}
		});
	},
	select: function(event, ui) {
		$('#featured-product' + ui.item.value).remove();
		$('#featured-product').append('<div id="featured-product' + ui.item.value + '">' + ui.item.label + '<img src="view/image/delete.png" alt="" /><input name="options[products][]" type="hidden" value="' + ui.item.value + '" /></div>');
		$('#featured-product div:odd').attr('class', 'odd');
		$('#featured-product div:even').attr('class', 'even');
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});

$('#featured-product div img').live('click', function() {
	$(this).parent().remove();

	$('#featured-product div:odd').attr('class', 'odd');
	$('#featured-product div:even').attr('class', 'even');
});
$('#made-for').change(function(){
	var id = $(this).val();
	$('.dependency > div').hide();
	$('.dependency').children('.'+id).show();
})
//--></script> 
<?php echo $footer; ?>